package at.fhj.itm10.ticketmaster.beans;

import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.faces.bean.RequestScoped;

import at.fhj.itm10.ticketmaster.dao.DAOException;
import at.fhj.itm10.ticketmaster.dao.TicketDAO;
import at.fhj.itm10.ticketmaster.entities.Ticket;
import at.fhj.itm10.ticketmaster.services.ServiceFactory;
import at.fhj.itm10.ticketmaster.services.TicketService;

/**
 * @author 	Kevin Reinmueller
 * @since	November 2012
 */

@ManagedBean
@RequestScoped
public class TicketBean {

	private TicketDAO dao;
	private Ticket ticket;
	private TicketService service;
	
	/**
	 *  initializing Bean
	 */
	public TicketBean() {
		super();
		init();
	}
	
	/**
	 * ticketservice object for ticket operations
	 */
	@PostConstruct
	public void init(){
		ServiceFactory factory = new ServiceFactory();
		service = factory.getTicketService();
	}

	public TicketDAO getDao() {
		return dao;
	}

	public void setDao(TicketDAO dao) {
		this.dao = dao;
	}

	public Ticket getTicket() {
		return ticket;
	}

	public void setTicket(Ticket ticket) throws DAOException {
		this.ticket = ticket;
		service.insertTicket(ticket);
	}

}
